package com.example.tome.module_base.base;

import android.app.Application;
import android.content.Context;

import com.example.tome.module_base.BuildConfig;

/**
 * @Created by TOME .
 * @时间 2018/4/26 16:35
 * @描述 ${保存全局变量设计的基本类application}
 */

public class CommonApplication extends Application{

    public static boolean IS_DEBUG = BuildConfig.DEBUG;
    private ActivityControl activityControl;//Activity管理
    private static CommonApplication commonApplication;

    public ActivityControl getActivityControl() {
        return activityControl;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        commonApplication  = this ;
    }

    public static CommonApplication getApplication(){
        return commonApplication;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        activityControl = new ActivityControl();

    }

    // 程序终止的时候执行
    @Override
    public void onTerminate() {
        super.onTerminate();
        exitApp();
    }

    /**
     * 退出应用
     */
    public void exitApp() {
        activityControl.finishiAll();
        android.os.Process.killProcess(android.os.Process.myPid());
        System.exit(0);
        commonApplication = null;
    }

    //低内存的时候执行
    @Override
    public void onLowMemory() {
        super.onLowMemory();

    }

    // 程序在内存清理的时候执行
    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);

    }
}
